home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / imap / non-ANSI / c-client / strtok.c < prev    next >
C/C++ Source or Header  |  1994-09-13  |  2KB  |  63 lines

  1. /*
  2.  * Program:    String return successive tokens
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *
  11.  * Date:    11 May 1989
  12.  * Last Edited:    12 September 1994
  13.  *
  14.  * Copyright 1994 by the University of Washington
  15.  *
  16.  *  Permission to use, copy, modify, and distribute this software and its
  17.  * documentation for any purpose and without fee is hereby granted, provided
  18.  * that the above copyright notice appears in all copies and that both the
  19.  * above copyright notice and this permission notice appear in supporting
  20.  * documentation, and that the name of the University of Washington not be
  21.  * used in advertising or publicity pertaining to distribution of the software
  22.  * without specific, written prior permission.  This software is made
  23.  * available "as is", and
  24.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  25.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  26.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  27.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  28.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  29.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  30.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  31.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  32.  *
  33.  */
  34.  
  35. /* Find token in string
  36.  * Accepts: source pointer or NIL to use previous source
  37.  *        vector of token delimiters pointer
  38.  * Returns: pointer to next token
  39.  */
  40.  
  41. static char *ts = NIL;        /* string to locate tokens */
  42.  
  43. char *strtok (s,ct)
  44.      char *s;
  45.      char *ct;
  46. {
  47.   char *t;
  48.   if (!s) s = ts;        /* use previous token if none specified */
  49.   if (!(s && *s)) return NIL;    /* no tokens */
  50.                 /* find any leading delimiters */
  51.   do for (t = ct, ts = NIL; *t; t++) if (*t == *s) {
  52.     if (*(ts = ++s)) break;    /* yes, restart seach if more in string */
  53.     return ts = NIL;        /* else no more tokens */
  54.   } while (ts);            /* continue until no more leading delimiters */
  55.                 /* can we find a new delimiter? */
  56.   for (ts = s; *ts; ts++) for (t = ct; *t; t++) if (*t == *ts) {
  57.     *ts++ = '\0';        /* yes, tie off token at that point */
  58.     return s;            /* return our token */
  59.   }
  60.   ts = NIL;            /* no more tokens */
  61.   return s;            /* return final token */
  62. }
  63.